<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // var arrFirst = [4, 9, 5, 8, 8];
    // var arrSecond = [9, 4, 9, 8, 4];
    // var res = [];
    // for (var i = 0; i < arrFirst.length; i++) {
    //   for (var j = 0; j < arrSecond.length; j++) {
    //     if (arrFirst[i] === arrSecond[j]) {
    //       res.push(arrFirst[i])
    //     }
    //   }
    //   var s = [...new Set(res)]
    // }
    // console.log(s)



    function array(a, b) {
      return [...new Set(a)].filter((a) => {
        //查看是否相同
        return b.includes(a)
      })

    }
    console.log(array([4, 9, 5, 8, 8], [4, 9, 5, 8, 4]))
  </script>
</body>

</html>